﻿using System.Collections.Generic;
using System.Data;

namespace TfsReports.Web.Models
{
    /// <summary>
    /// Person
    /// </summary>
    public class Person : Entity
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="dataRecord">The data record.</param>
        public Person(IDataRecord dataRecord)
        {
            Id = dataRecord.GetInt32(dataRecord.GetOrdinal("PersonId"));
            Title = dataRecord.GetString(dataRecord.GetOrdinal("PersonTitle"));
        }

        public static List<Person> GetAll(List<Churn> churns)
        {
            List<Person> people = new List<Person>();
            churns.ForEach(c=> {
                                   if(people.Find(p=>p.Id == c.Person.Id)==null)
                                       people.Add(c.Person);
                               });
            return people;
        }
    }
}
